﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BibleService.Lib
{
	/// <summary>
	/// 圣灵注释
	/// </summary>
	public class Commentary
	{
		public int CommentaryID{get;set;}
		public int BookID{get;set;}
		public string BookName{get;set;}
		public int ChapterID{get;set;}
		public int ChapterNumber{get;set;}
		public string Content{get;set;}
		
		public void Add()
		{
			string selectSql = string.Format("Insert into Commentary(BookID,BookName,ChapterID,ChapterNumber,Content) values('{0}','{1}','{2}','{3}','{4}')",
				this.BookID,
				this.BookName,
				this.ChapterID,
				this.ChapterNumber,
				this.Content
			);			
			_SqlHelper.Execute(selectSql);			
		}
		/// <summary>
		/// 获取指定章的注释内容
		/// </summary>
		/// <param name="bookId"></param>
		/// <param name="chapterNumber"></param>
		/// <returns></returns>
		public static Commentary GetCommentary(int bookId, int chapterNumber)
		{
			string selectSql = string.Format("select  * from Commentary where BookID='{0}' and ChapterNumber='{1}' limit 0,1", bookId, chapterNumber);			
			var datarReader=_SqlHelper.GetSingRecord(selectSql);
			if(datarReader==null)
				return null;
			var model = new Commentary();
			model.CommentaryID = datarReader.GetInt32(0);
			model.BookID = datarReader.GetInt32(1);
			model.BookName = datarReader.GetString(2);
			model.ChapterID = datarReader.GetInt32(3);
			model.ChapterNumber = datarReader.GetInt32(4);
			model.Content = datarReader.GetString(5);
			datarReader.Close();
			return model;
		}
	}
}
